/*
 * @Author: HuangYue
 * @Date: 2022-02-27 14:57:19
 * @LastEditors: HuangYue
 * @LastEditTime: 2022-04-16 17:13:31
 * @FilePath: /graduation/src/services/mockApi/peopleManage.js
 * @Description:用户信息api
 */
// import { request } from 'umi';
// import tableListDataSource from '@/mock/peopleManage';
import {
  getTableDataForHospital,
  waitTime,
  uidBase,
  avatar,
} from '../../../../../mock/peopleManage';

let hospitalTableData = getTableDataForHospital();
let idBase = uidBase;
// todo:持久化保存数据

/**
 * 医院用户 - 人员管理相关接口
 */
/**
 * 获取所有的人员
 */
export async function getAllPeople() {
  return Promise.resolve({
    success: true,
    data: hospitalTableData,
    total: hospitalTableData.length,
  });
}
/**
 * 通过uid删除指定的人员
 */
export async function deletePeopleByUid(parmas, options) {
  const { uid } = parmas;
  const temp = [];
  hospitalTableData.forEach((item) => {
    if (item.uid !== uid) {
      temp.push(item);
    }
  });
  hospitalTableData = temp;
  await waitTime(2000);
  return Promise.resolve({
    success: true,
    data: hospitalTableData,
    total: hospitalTableData.length,
  });
}
/**
 * 更新人员信息
 */
export async function updatePeople(parmas, options) {
  const current = parmas;
  const temp = [];
  hospitalTableData.forEach((item) => {
    if (item.uid === current.uid) {
      temp.push(current);
    } else {
      temp.push(item);
    }
  });
  await waitTime(2000);
  hospitalTableData = temp;
  return Promise.resolve({
    success: true,
    data: hospitalTableData,
    total: hospitalTableData.length,
  });
}
/**
 * 添加人员
 */
export async function addPeople(parmas, options) {
  const current = parmas;
  idBase += 1;
  const temp = [];
  temp.push({ ...current, uid: uidBase, avatar: avatar[0] });
  hospitalTableData.forEach((item) => {
    temp.push(item);
  });
  hospitalTableData = temp;
  await waitTime(2000);
  return Promise.resolve({
    success: true,
    data: hospitalTableData,
    total: hospitalTableData.length,
  });
}
